//
//  QShowSubWebView.m
//  QoilPublic
//
//  Created by 杨凯 on 16/11/25.
//  Copyright © 2016年 杨凯. All rights reserved.
//

#import "QShowSubWebView.h"

@interface QShowSubWebView()<UIWebViewDelegate>

@property (weak, nonatomic) IBOutlet UIWebView *webView;

@property (weak, nonatomic) IBOutlet UIView *bacView;

@property (weak, nonatomic) IBOutlet UIButton *btn;



@end
@implementation QShowSubWebView


- (void)awakeFromNib{
    
    [super awakeFromNib];
    _bacView.layer.cornerRadius = 4.0;
    _webView.delegate = self;
    _webView.layer.cornerRadius = 4.0;
    _webView.backgroundColor = [UIColor whiteColor];
    _webView.width = 280;
    _webView.height = 255;
    _webView.scalesPageToFit = YES;
    
    
    
    for (UIView *_aView in [_webView subviews])
    {
        if ([_aView isKindOfClass:[UIScrollView class]])
        {
            [(UIScrollView *)_aView setShowsVerticalScrollIndicator:NO];
            //右侧的滚动条
            
            [(UIScrollView *)_aView setShowsHorizontalScrollIndicator:NO];
            //下侧的滚动条
            
            for (UIView *_inScrollview in _aView.subviews)
            {
                if ([_inScrollview isKindOfClass:[UIImageView class]])
                {
                    _inScrollview.hidden = YES;  //上下滚动出边界时的黑色的图片
                }
            }
        }
    }
}


- (void)setUrl:(NSString *)url{
    _url = url;
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:_url]];
    [_webView loadRequest:request];

}

- (IBAction)btnAction:(id)sender {
    
    if(_block){
        _block();
    }
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    
    return YES;
}

- (void)webViewDidFinishLoad:(UIWebView *)theWebView{
        NSString *javascript = [NSString stringWithFormat:@"var viewPortTag=document.createElement('meta');  \
                      viewPortTag.id='viewport';  \
                      viewPortTag.name = 'viewport';  \
                      viewPortTag.content = 'width=%d; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;';  \
                      document.getElementsByTagName('head')[0].appendChild(viewPortTag);" ,(int)_webView.width];
    
        [_webView stringByEvaluatingJavaScriptFromString:javascript];

}


@end
